package com.wjh.kt_vod.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjh.kt_vod.model.vod.Course;
import com.wjh.kt_vod.result.Result;
import com.wjh.kt_vod.service.CourseService;
import com.wjh.kt_vod.vo.vod.CourseFormVo;
import com.wjh.kt_vod.vo.vod.CoursePublishVo;
import com.wjh.kt_vod.vo.vod.CourseQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "课程信息管理")
@RestController
@RequestMapping("/admin/vod/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @ApiOperation(value = "课程信息分页查询")
    @GetMapping("/{page}/{limit}")
    public Result pageCourse(@PathVariable("page")
                                 @ApiParam(name = "page" ,value = "当前页" ,required = true) Long page
           , @PathVariable("limit")
                                 @ApiParam(name = "limit" ,value = "每页记录数" ,required = true) Long limit
            , @ApiParam(name = "courseVo", value = "查询对象", required = false) CourseQueryVo courseQueryVo){

        Page<Course> coursePage = new Page<>(page, limit);

       Map<String,Object> course=courseService.findPageCourse(coursePage,courseQueryVo);
       return Result.ok(course);
    }

    @ApiOperation(value = "添加课程信息")
    @PostMapping("/save")
    public Result saveCourse(@RequestBody CourseFormVo courseFormVo){
       Long couseId = courseService.saveCourseInfo(courseFormVo);
       return Result.ok(couseId);
    }

    /**
     *
     */
    @ApiOperation(value = "根据id获取课程信息")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Long id){
        CourseFormVo courseFormVoById = courseService.getCourseFormVoById(id);
        return Result.ok(courseFormVoById);
    }

    @ApiOperation("修改课程信息")
    @PostMapping("/update")
    public Result update(@RequestBody CourseFormVo courseFormVo){
        courseService.updateCourseById(courseFormVo);
        return Result.ok(courseFormVo.getId());
    }

    @ApiOperation("根据id获取课程发布信息")
    @GetMapping("getCoursePublishVo/{id}")
    public Result getCoursePublishVo(@PathVariable("id") Long id){
        CoursePublishVo coursePublishVo = courseService.getCoursePublishVo(id);
        return Result.ok(coursePublishVo);
    }

    @ApiOperation("课程最终发布")
    @PutMapping("/publishCourse/{id}")
    public Result publishCourse(@PathVariable("id") Long id){
        courseService.publishCourse(id);
        return Result.ok();
    }

    @ApiOperation(value = "删除课程")
    @DeleteMapping("/remove/{id}")
    public Result remove(@PathVariable("id") Long id){
        courseService.removeCourseById(id);
        return Result.ok();
    }
}
